//
//  HTMUserDefaultManager.m
//  QVBusUser
//
//  Created by Ting Han on 2017/7/24.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "HTMUserDefaultManager.h"

@implementation HTMUserDefaultManager

// 存储用户偏好设置
+ (void)saveUserData:(id)data forKey:(NSString *)key {
    [[NSUserDefaults standardUserDefaults] setObject:data forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
+ (void)saveUserIntegerData:(NSInteger)data forKey:(NSString *)key{
    [[NSUserDefaults standardUserDefaults] setInteger:data forKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
}


// 读取用户偏好设置
+ (id)readUserDataForKey:(NSString *)key {
    id obj = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return obj;
    
}
+ (NSInteger)readUserIntegerForKey:(NSString *)key{
    NSInteger obj = [[NSUserDefaults standardUserDefaults] integerForKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
    return obj;
}

// 删除用户偏好设置
+ (void)removeUserDataForkey:(NSString *)key {
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
    [[NSUserDefaults standardUserDefaults] synchronize];
    //直接同步到设置中,防止程序意外退出,造成数据丢失
}
//返回M
+(long long)fileCatchSize{
    NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    NSString *filePath = [cachePath stringByAppendingPathComponent:@"cacheData.sqlite"];
    NSFileManager* manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:filePath]){
        return [[manager attributesOfItemAtPath:filePath error:nil]fileSize]/(1024.0*1024.0);
    }
    return 0;
}


@end
